/*
* Conditions Of Use
*
* This software was developed by employees of the Sigmatrix(Beijing) Corporation.
* This software is provided by sigmatrix as a service and is expressly
* provided "AS IS."  Sigmatrix MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT
* AND DATA ACCURACY.  Sigmatrix does not warrant or make any representations
* regarding the use of the software or the results thereof, including but
* not limited to the correctness, accuracy, reliability or usefulness of
* the software.
*
* Permission to use this software is contingent upon your acceptance
* of the terms of this agreement.
*
*/
package com.sigmatrix.h5.service.impl;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.sigmatrix.h5.dao.SysConfigDao;
import com.sigmatrix.h5.dto.VersionData;
import com.sigmatrix.h5.entity.Version;
import com.sigmatrix.h5.enums.ResponseEnum;
import com.sigmatrix.h5.exception.ServiceException;
import com.sigmatrix.h5.response.Response;
import com.sigmatrix.h5.service.VersionService;
import com.sigmatrix.h5.service.common.impl.BaseServiceImpl;
import com.sigmatrix.h5.utils.Cons;
import com.sigmatrix.h5.utils.Utils;
import com.sigmatrix.h5.web.vo.VersionVo;

/**
 *@ClassName: VersionServiceImpl
 *@Description: 
 *@date 2017年8月9日 上午1:16:26
 */
@Service(value = "versionService")
public class VersionServiceImpl extends BaseServiceImpl<VersionData> implements VersionService {
	/** logger record */
	private static final Logger LOGGER = LoggerFactory.getLogger(VersionServiceImpl.class);

	@Autowired
	private transient SysConfigDao sysConfigDao;

	@Override
	public Response getVersion(final VersionVo versionVo) throws ServiceException {
		try {
			String key = "app_version_and";//获取安卓版本信息
			if(Cons.APP_TYPE_IOS==versionVo.getAppType()){
				key = "app_version_ios";//获取ios版本信息
			}
			String value = sysConfigDao.getValueByKey(versionVo.getEnterpriseCode(), key);
			if(Utils.isEmpty(value)){
				return new Response(ResponseEnum.NO_DATA);
			}
			final Version version = JSON.parseObject(value, Version.class);
			final VersionData versionDto = new VersionData();
			BeanUtils.copyProperties(version,versionDto);
			return new Response(ResponseEnum.SUCCESS,versionDto);
		} catch (Exception e) {
			LOGGER.error("获取版本号接口失败", e);
			throw new ServiceException(e);
		}
		
	}

	

}
